package culaocham.sinhvat.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.bo.ProcessBO;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class UpdateDataAction extends Action{
	String message;
	ProcessBO processBO;

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		message = new String(request.getParameter("message"));
		processBO = new ProcessBO();
		if("them moi thuc vat".equals(message)){
			String tvloai = new String(request.getParameter("tvloai").getBytes("ISO8859_1"), "UTF8");
			String tvho = new String(request.getParameter("tvho").getBytes("ISO8859_1"), "UTF8");
			String tvchieucao = new String(request.getParameter("tvchieucao").getBytes("ISO8859_1"), "UTF8");
			String tvduongkinh = new String(request.getParameter("tvduongkinh").getBytes("ISO8859_1"), "UTF8");
			String tvloaisinhtruong = new String(request.getParameter("tvloaisinhtruong").getBytes("ISO8859_1"), "UTF8");
			String tvdangsong = new String(request.getParameter("tvdangsong").getBytes("ISO8859_1"), "UTF8");
			String tvdongtay = new String(request.getParameter("tvdongtay").getBytes("ISO8859_1"), "UTF8");
			String tvnambac = new String(request.getParameter("tvnambac").getBytes("ISO8859_1"), "UTF8");
			double tvlatatude = new Double(request.getParameter("tvlatatude"));
			double tvlongatude = new Double(request.getParameter("tvlongatude"));
			boolean tvgtgo = new Boolean(request.getParameter("tvgtgo"));
			boolean tvgtcanh = new Boolean(request.getParameter("tvgtcanh"));
			boolean tvgtthuoc = new Boolean(request.getParameter("tvgtthuoc"));
			boolean tvgtvlxaydung = new Boolean(request.getParameter("tvgtvlxaydung"));
			boolean tvgtthucongmynghe = new Boolean(request.getParameter("tvgtthucongmynghe"));
			boolean tvgtanduoc = new Boolean(request.getParameter("tvgtanduoc"));
			boolean tvgtcaydoc = new Boolean(request.getParameter("tvgtcaydoc"));
			boolean tvgtchotinhdau = new Boolean(request.getParameter("tvgtchotinhdau"));
			boolean tvgtnhua = new Boolean(request.getParameter("tvgtnhua"));
			boolean tvgtsoi = new Boolean(request.getParameter("tvgtsoi"));
			boolean tvgthuocnhuom = new Boolean(request.getParameter("tvgthuocnhuom"));
			boolean tvgtcongdungkhac = new Boolean(request.getParameter("tvgtcongdungkhac"));
			String tvdacdiem = new String(request.getParameter("tvdacdiem").getBytes("ISO8859_1"), "UTF8");
			String tvimage = new String(request.getParameter("tvimage").getBytes("ISO8859_1"), "UTF8");
			
			processBO.addThucvat(tvloai, tvho, tvchieucao, tvduongkinh,
					tvloaisinhtruong, tvdangsong, tvdongtay, tvnambac, tvlatatude,
					tvlongatude, tvgtgo, tvgtcanh, tvgtthuoc, tvgtvlxaydung,
					tvgtthucongmynghe, tvgtanduoc, tvgtcaydoc, tvgtchotinhdau,
					tvgtnhua, tvgtsoi, tvgthuocnhuom, tvgtcongdungkhac, tvdacdiem, tvimage);
			
		} else if("them 1 ca the thuc vat".equals(message)){
			int tvid = new Integer(request.getParameter("tvid"));
			double tvlatatude = new Double(request.getParameter("tvlatatude"));
			double tvlongatude = new Double(request.getParameter("tvlongatude"));
			processBO.addViTriThucVat(tvid, tvlatatude, tvlongatude);
			
		} else if("xoa 1 ca the thuc vat".equals(message)){
			double tvlatatude = new Double(request.getParameter("tvlatatude"));
			double tvlongatude = new Double(request.getParameter("tvlongatude"));
			processBO.deleteThucVat(tvlatatude, tvlongatude, 0, null);
			
		} else if("xoa loai thuc vat".equals(message)){
			int tvid = new Integer(request.getParameter("tvid"));
			processBO.deleteThucVat(0, 0, tvid, null);
			
		} else if("xoa ho thuc vat".equals(message)){
			String tvho = new String(request.getParameter("tvho").getBytes("ISO8859_1"), "UTF8");
			processBO.deleteThucVat(0, 0, 0, tvho);
		} else if("sua thong tin thuc vat".equals(message)){
			int tvid = new Integer(request.getParameter("tvid"));
			String tvloai = new String(request.getParameter("tvloai").getBytes("ISO8859_1"), "UTF8");
			String tvho = new String(request.getParameter("tvho").getBytes("ISO8859_1"), "UTF8");
			String tvchieucao = new String(request.getParameter("tvchieucao").getBytes("ISO8859_1"), "UTF8");
			String tvduongkinh = new String(request.getParameter("tvduongkinh").getBytes("ISO8859_1"), "UTF8");
			String tvloaisinhtruong = new String(request.getParameter("tvloaisinhtruong").getBytes("ISO8859_1"), "UTF8");
			String tvdangsong = new String(request.getParameter("tvdangsong").getBytes("ISO8859_1"), "UTF8");
			String tvdongtay = new String(request.getParameter("tvdongtay").getBytes("ISO8859_1"), "UTF8");
			String tvnambac = new String(request.getParameter("tvnambac").getBytes("ISO8859_1"), "UTF8");
			double tvlatatude = new Double(request.getParameter("tvlatatude"));
			double tvlongatude = new Double(request.getParameter("tvlongatude"));
			double tvlatatudeold = new Double(request.getParameter("tvlatatudeold"));
			double tvlongatudeold = new Double(request.getParameter("tvlongatudeold"));
			boolean tvgtgo = new Boolean(request.getParameter("tvgtgo"));
			boolean tvgtcanh = new Boolean(request.getParameter("tvgtcanh"));
			boolean tvgtthuoc = new Boolean(request.getParameter("tvgtthuoc"));
			boolean tvgtvlxaydung = new Boolean(request.getParameter("tvgtvlxaydung"));
			boolean tvgtthucongmynghe = new Boolean(request.getParameter("tvgtthucongmynghe"));
			boolean tvgtanduoc = new Boolean(request.getParameter("tvgtanduoc"));
			boolean tvgtcaydoc = new Boolean(request.getParameter("tvgtcaydoc"));
			boolean tvgtchotinhdau = new Boolean(request.getParameter("tvgtchotinhdau"));
			boolean tvgtnhua = new Boolean(request.getParameter("tvgtnhua"));
			boolean tvgtsoi = new Boolean(request.getParameter("tvgtsoi"));
			boolean tvgthuocnhuom = new Boolean(request.getParameter("tvgthuocnhuom"));
			boolean tvgtcongdungkhac = new Boolean(request.getParameter("tvgtcongdungkhac"));
			String tvdacdiem = new String(request.getParameter("tvdacdiem").getBytes("ISO8859_1"), "UTF8");
			String tvimage = new String(request.getParameter("tvimage").getBytes("ISO8859_1"), "UTF8");
			processBO.editThucvat(tvid, tvloai, tvho, tvchieucao, tvduongkinh,
					tvloaisinhtruong, tvdangsong, tvdongtay, tvnambac,
					tvlatatude, tvlatatudeold, tvlongatude, tvlongatudeold, 
					tvgtgo, tvgtcanh, tvgtthuoc, tvgtvlxaydung,
					tvgtthucongmynghe, tvgtanduoc, tvgtcaydoc, tvgtchotinhdau,
					tvgtnhua, tvgtsoi, tvgthuocnhuom, tvgtcongdungkhac,
					tvdacdiem, tvimage);
		} else if("them moi dong vat".equals(message)){
			String dvloai = new String(request.getParameter("dvloai").getBytes("ISO8859_1"), "UTF8");
			String dvho = new String(request.getParameter("dvho").getBytes("ISO8859_1"), "UTF8");
			String dvgioi = new String(request.getParameter("dvgioi").getBytes("ISO8859_1"), "UTF8");
			String dvnganh = new String(request.getParameter("dvnganh").getBytes("ISO8859_1"), "UTF8");
			String dvlop = new String(request.getParameter("dvlop").getBytes("ISO8859_1"), "UTF8");
			String dvbo = new String(request.getParameter("dvbo").getBytes("ISO8859_1"), "UTF8");
			String dvchi = new String(request.getParameter("dvchi").getBytes("ISO8859_1"), "UTF8");
			boolean dvnstrencan = new Boolean(request.getParameter("dvnstrencan"));
			boolean dvnstrencay = new Boolean(request.getParameter("dvnstrencay"));
			boolean dvnsduoinuoc = new Boolean(request.getParameter("dvnsduoinuoc"));
			double dvlatatude = new Double(request.getParameter("dvlatatude"));
			double dvlongatude = new Double(request.getParameter("dvlongatude"));
			String dvthucan = new String(request.getParameter("dvthucan").getBytes("ISO8859_1"), "UTF8");
			String dvdacdiem = new String(request.getParameter("dvdacdiem").getBytes("ISO8859_1"), "UTF8");
			String dvimage = new String(request.getParameter("dvimage").getBytes("ISO8859_1"), "UTF8");
			
			processBO.addDongvat(dvloai, dvho, dvgioi, dvnganh, dvlop,
					dvbo, dvchi, dvthucan, dvdacdiem, dvlatatude, dvlongatude,
					dvnstrencan, dvnstrencay, dvnsduoinuoc, dvimage);
			
		} else if("them 1 ca the dong vat".equals(message)){
			int dvid = new Integer(request.getParameter("dvid"));
			double dvlatatude = new Double(request.getParameter("dvlatatude"));
			double dvlongatude = new Double(request.getParameter("dvlongatude"));
			processBO.addViTriDongVat(dvid, dvlatatude, dvlongatude);
			
		} else if("xoa 1 ca the dong vat".equals(message)){
			double dvlatatude = new Double(request.getParameter("dvlatatude"));
			double dvlongatude = new Double(request.getParameter("dvlongatude"));
			processBO.deleteDongVat(dvlatatude, dvlongatude, 0, null);
			
		} else if("xoa loai dong vat".equals(message)){
			int dvid = new Integer(request.getParameter("dvid"));
			processBO.deleteDongVat(0, 0, dvid, null);
			
		} else if("xoa ho dong vat".equals(message)){
			String dvho = new String(request.getParameter("dvho").getBytes("ISO8859_1"), "UTF8");
			processBO.deleteDongVat(0, 0, 0, dvho);
		} else if("sua thong tin dong vat".equals(message)){
			int dvid = new Integer(request.getParameter("dvid"));
			String dvloai = new String(request.getParameter("dvloai").getBytes("ISO8859_1"), "UTF8");
			String dvho = new String(request.getParameter("dvho").getBytes("ISO8859_1"), "UTF8");
			String dvgioi = new String(request.getParameter("dvgioi").getBytes("ISO8859_1"), "UTF8");
			String dvnganh = new String(request.getParameter("dvnganh").getBytes("ISO8859_1"), "UTF8");
			String dvlop = new String(request.getParameter("dvlop").getBytes("ISO8859_1"), "UTF8");
			String dvbo = new String(request.getParameter("dvbo").getBytes("ISO8859_1"), "UTF8");
			String dvchi = new String(request.getParameter("dvchi").getBytes("ISO8859_1"), "UTF8");
			boolean dvnstrencan = new Boolean(request.getParameter("dvnstrencan"));
			boolean dvnstrencay = new Boolean(request.getParameter("dvnstrencay"));
			boolean dvnsduoinuoc = new Boolean(request.getParameter("dvnsduoinuoc"));
			double dvlatatude = new Double(request.getParameter("dvlatatude"));
			double dvlatatudeold = new Double(request.getParameter("dvlatatudeold"));
			double dvlongatude = new Double(request.getParameter("dvlongatude"));
			double dvlongatudeold = new Double(request.getParameter("dvlongatudeold"));
			String dvthucan = new String(request.getParameter("dvthucan").getBytes("ISO8859_1"), "UTF8");
			String dvdacdiem = new String(request.getParameter("dvdacdiem").getBytes("ISO8859_1"), "UTF8");
			String dvimage = new String(request.getParameter("dvimage").getBytes("ISO8859_1"), "UTF8");
			processBO.editDongvat(dvid, dvloai, dvho, dvgioi, dvnganh, dvlop,
					dvbo, dvchi, dvthucan, dvdacdiem, dvlatatude,
					dvlatatudeold, dvlongatude, dvlongatudeold, dvnstrencan,
					dvnstrencay, dvnsduoinuoc, dvimage);
		}
		
		return null;
	}
	
}
